package com.zzptc.myk.myapplication;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class RegActivity extends AppCompatActivity {
    Button btn_reg;
    Button btn_reset;
    EditText et_name;
    EditText et_pwd1;
    EditText et_pwd2;
    private static final String TAG = "RegActivity";


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_reg);
        init();
        event();

    }
    public void event(){
        btn_reg.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //Log.d(TAG,"点击了我");
                //准备回传 1,获取值 2，保存值到意图 3，回传
                String username = et_name.getText().toString().trim();
                String password = et_pwd1.getText().toString().trim();
                String password2 = et_pwd2.getText().toString().trim();

                if(password.equals(password2)) {

                    if (username.equals("") || password.equals("")) {
                        Toast.makeText(RegActivity.this, "用户名和密码不能为空", Toast.LENGTH_SHORT).show();


                    } else {
                        Log.d(TAG, username);
                        Intent intent = new Intent();
                        intent.putExtra("uname", username);
                        intent.putExtra("pwd", password);
                        setResult(2, intent);
                        finish();
                    }
                }else {
                    Toast.makeText(RegActivity.this, "两次密码不一样", Toast.LENGTH_SHORT).show();
                }
            }
        });
    }
    public void init() {
        btn_reg = findViewById(R.id.btn_reg_ok);
        et_name = findViewById(R.id.et_name1);
        btn_reset = findViewById(R.id.btn_reset);
        et_pwd1 = findViewById(R.id.et_pwd1);
        et_pwd2 = findViewById(R.id.et_pwd2);
    }


}
